<?php
	//修改用户绑定号码接口-set_number.php
	//http://42.121.57.193:7788/platform/set_number.php?oldphone=18665986379&newphone=15507558558

	include_once "init.php";

	$old_phone 		= $_GET["oldphone"];
	$new_phone		= $_GET["newphone"];

	if(''==$old_phone)
	{
		die("-1|原手机号码不可以为空");
	}
	if(''==$new_phone)
	{
		die("-1|新手机号码不可以为空");
	}
	if (strlen($old_phone) != 11 || false==is_numeric($old_phone) || ord($old_phone)!=49)
	{
		die("-1|手机号码必须是11位数字，并且以1开头");
	}
	if (strlen($new_phone) != 11 || false==is_numeric($new_phone) || ord($new_phone)!=49)
	{
		die("-1|手机号码必须是11位数字，并且以1开头");
	}

	if($old_phone == $new_phone)
	{
		die("1|新手机号码和原手机号码重复");
	}

	$con    = db_connect(DB_NAME);
	//先获取配置信息，查看号码是否存在
	$res = mysql_query("SELECT uuid,phone FROM user where band_phone='$old_phone'") or die("-1|查询数据库失败");
	$row = mysql_fetch_row($res);

	if (empty($row))
	{
		mysql_close($con);
		die("-1|原手机号码未注册");
	}

	//更新操作
	$res = mysql_query("UPDATE user SET band_phone='$new_phone' where band_phone='$old_phone'") or die("-1|查询数据库失败");

	if ( $res === false )
	{
		mysql_close($con);
		die("-1|设置新手机号码失败");
	}
	mysql_close($con);
	//修改电话卡绑定号码
	$type 				= '0';
	$e164 				= $new_phone;
	$activePhoneCard 	= 'c_'.$row['0'];
	$loginName	   		= VOS_USER;
	$loginPassword 		= VOS_PW;



	//VOS接口--电话卡绑定号码-修改
	setbindede164('2',$old_phone,$activePhoneCard,$loginName,$loginPassword);

	$result = setbindede164($type,$e164,$activePhoneCard,$loginName,$loginPassword);
	
	if('0'!=$result[0]&&'|'!=$result[1])
	{
		die("-1|设置绑定号码失败");
	}
	else
	{
		echo '0|';
	}

?>